home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeeds.ans.net!philabs!usenet
- From: abf@philabs.research.philips.com (Andrew Feldman)
- Newsgroups: comp.lang.c++
- Subject: Re: callback function in a class
- Date: Wed, 14 Feb 1996 21:03:18 GMT
- Organization: Philips Laboratories, Briarcliff, NY 10510
- Distribution: inet
- Message-ID: <4ft814$hde@philabs.research.philips.com>
- References: <4fe0lk$cu3@aldebaran.sct.fr> <Pine.OSF.3.91.960214160359.19924A-100000@stio1>
- NNTP-Posting-Host: idrpc5.philabs.research.philips.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Schmidt Carsten <i010@stio1> wrote:
-
-
- >Hi, everybody,
-
- >Does anybody have an idea, how I can put a callback function in a class,
- >look for the example:
-
- >class X {
- > DWORD ThreadProc (..parms...);
- > void StartIt (void);
- >...
- >};
-
- >DWORD X::ThreadProc (...parms...)
- >{
- > ....
- >}
-
- >void X::StartIt (void)
- >{
- > hThread = CreateThread (..., ThreadProc, ...);
- >}
-
- >Don't worry about Threads, it is just an example. I try to find a
- >solution for the general problem: How to use a callback-function in a class.
-
- >I think some programmers know the problem.
-
- >Ciao,
- >Carsten.
- > ____________________________________________________________
- > / Carsten SCHMIDT /
- > / student of computer science /
- > / Fachhochschule Wuerzburg-Schweinfurt-Aschaffenburg /
- > / Friedenstr. 2/1715, 97072 Wuerzburg, Germany /
- > / Tel: +49 931 800 56 07, Fax: +49 931 610 14 68 /
- > / E-Mail: i010@stio1.fh-wuerzburg.de /
- >/___________________________________________________________/
-
-
- For CreateThread purposes (actually in many other cases also) I'd do
- the following. Define a static member function or just a global
- function GenericThreadProc:
-
- GenericThreadProc(X* x)
- { x->ThreadProc() }
-
- ThreadProc can't have parameters, they should be passes in the data
- members of x. In the StartIt(), you do
-
- hThread = CreateThread (..., GenericThreadProc, this ...);
-
- Functions like CreateThread always have as their parameter not only a
- pointer to the callback function, but also a void* or char* pointer
- which is gonna be used as a parameter to this callback function.
-
- You know, this is only the idea (which worked -- guaranteed). You
- should work out the details. For example, callback function is not
- supposed to be of type (*)(X*), so you may have to add additional
- parameters to its header and do some type conversions.
-
- Andrew.
-
-
-